package com.example.controller;


import com.example.pojo.Brand;
import com.example.pojo.PageBean;
import com.example.tools.Result;
import com.example.pojo.GoodType;
import com.example.service.impl.GoodTypeImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/admin")
public class GoodTypeController {
    @Autowired
    private GoodTypeImpl goodTypeService;

    /**
     * 获取商品分类信息
     * @return
     */
    @PostMapping("/getGoodType")
    public Result getGoodType(
        @RequestBody GoodType goodType,
        @RequestParam(defaultValue = "1") Integer page,
        @RequestParam(defaultValue = "10") Integer pageSize) {

            //log.info("supplier：{}",supplier);
            PageBean pageBean = goodTypeService.getGoodType(goodType,page, pageSize);
            //log.info("查询全部教徒数据,deptlist:{}",pageBean);
            return Result.success(pageBean);
    }

    @GetMapping("/getGoodTypeList")
    public Result getGoodType() {
        List<GoodType> goodTypeList = goodTypeService.getGoodTypeList();
        return Result.success(goodTypeList);
    }

    /**
     * 修改商品分类信息
     */
    @PostMapping("/changeGoodType")
    public Result changeGoodType(@RequestBody GoodType goodType){
        goodTypeService.changeGoodType(goodType);
        return Result.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/deleteGoodType")
    public Result deleteGoodType(String id){
        if(goodTypeService.deleteGoodType(id)!=0)
            return Result.success();
        else
            return Result.error("删除失败");
    }

    /**
     * 添加商品分类信息
     * @param goodType
     * @return
     */

    @PostMapping("/addGoodType")
    public Result addGoodType(@RequestBody GoodType goodType){
        goodTypeService.addGoodType(goodType);
        return Result.success();
    }

}
